home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bblc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-03-23  |  17.3 KB  |  440 lines

  1. (*===========================================================================*)
  2. (* Link change                                                               *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1989, 1990, 1991 by H. Roy Engehausen.  All rights      *)
  5. (*   reserved.                                                               *)
  6. (*                                                                           *)
  7. (*===========================================================================*)
  8.  
  9. {$O+}
  10.  
  11. UNIT BBLC;
  12.  
  13. INTERFACE
  14.  
  15. PROCEDURE link_start;
  16. PROCEDURE link_change;
  17. PROCEDURE link_pending;
  18.  
  19. IMPLEMENTATION
  20.  
  21.   USES
  22.     bbauxm,
  23.     bbdummy,
  24.     bblog,
  25.     bbmdata,
  26.     bbmess,
  27.     bbmisc4,
  28.     bbsess,
  29.     bbsrt,
  30.     bbstr,
  31.     bbtask,
  32.     bbuf,
  33.     bbwin;
  34.  
  35. (*===========================================================================*)
  36. (* Link Status Start                                                         *)
  37. (*===========================================================================*)
  38.  
  39. PROCEDURE link_start;
  40.  
  41.   VAR
  42.     i         : BYTE;
  43.     work_str  : STRING;
  44.  
  45.   BEGIN;
  46.  
  47.     WITH active_tcb^ DO
  48.       BEGIN;
  49.  
  50.         (*-------------------------------------------------------------------*)
  51.         (* Init any part of TCB as needed                                    *)
  52.         (*-------------------------------------------------------------------*)
  53.  
  54.         window  := window_connect;
  55.  
  56.         (*-------------------------------------------------------------------*)
  57.         (* Remove the channel number (if any)                                *)
  58.         (*-------------------------------------------------------------------*)
  59.  
  60.         IF tnc_data.str_data[1] = '(' THEN
  61.           tnc_data.str_data := subword(@tnc_data.str_data, 2, 0);
  62.  
  63.         (*-------------------------------------------------------------------*)
  64.         (* Verify that this is indeed a connect request.  Give error if not. *)
  65.         (*-------------------------------------------------------------------*)
  66.  
  67.         work_str := subword(@tnc_data.str_data, 1, 2) + ' ';
  68.  
  69.         IF (work_str <> t_to_h_ct) THEN
  70.           BEGIN;
  71.  
  72.             window_write(port_chan_s + 'E:', 'First item is not connect!');
  73.             window_write(port_chan_s + 'E:', work_str);
  74.             window_write(port_chan_s + 'E:', tnc_data.str_data);
  75.  
  76.             cmd_tnc(@disc_cmd, TRUE);
  77.  
  78.             REPEAT
  79.               work_str := garbage_collect_tnc;
  80.               IF LENGTH(work_str) <> 0 THEN
  81.                 window_write(port_chan_s + 'G:', tnc_data.str_data);
  82.             UNTIL LENGTH(work_str) = 0;
  83.  
  84.             i := 0;
  85.             REPEAT
  86.               INC(i);
  87.               send_recv_tnc(2);
  88.               IF NOT tnc_null THEN
  89.                 window_write(port_chan_s + 'E:', tnc_data.str_data);
  90.             UNTIL tnc_null OR (i > 30);
  91.  
  92.             task_destroy_active;
  93.  
  94.           END;
  95.  
  96.         (*-------------------------------------------------------------------*)
  97.         (* Process the link change                                           *)
  98.         (*-------------------------------------------------------------------*)
  99.  
  100.         link_change;
  101.  
  102.       END;
  103.  
  104.   END;
  105.  
  106. (*===========================================================================*)
  107. (* Link Status Change                                                        *)
  108. (*===========================================================================*)
  109.  
  110. PROCEDURE link_change;
  111.  
  112.   VAR
  113.     connect_call    : call_sign_str;
  114.     i               : BYTE;
  115.     connect_ssid    : ssid_sign_str;
  116.     new_user        : BOOLEAN;
  117.     pcpa_port       : CHAR;
  118.     this_port       : port_block_ptr;
  119.     t1_str          : STRING;
  120.     uid_i_current   : user_index_ptr;
  121.     work2_str       : STRING;
  122.     work3_str       : STRING;
  123.  
  124.   {$I BBLCA.PAS}
  125.  
  126.   BEGIN;
  127.  
  128.     WITH active_tcb^ DO
  129.       BEGIN;
  130.  
  131.         (*-------------------------------------------------------------------*)
  132.         (* Display                                                           *)
  133.         (*-------------------------------------------------------------------*)
  134.  
  135.         window_write(port_chan_s + 'L:', tnc_data.str_data);
  136.  
  137.         (*-------------------------------------------------------------------*)
  138.         (* If told to, we will ignore link changes                           *)
  139.         (*-------------------------------------------------------------------*)
  140.  
  141.         IF tcb_ignore_lc THEN
  142.           EXIT;
  143.  
  144.         (*-------------------------------------------------------------------*)
  145.         (* Remove the channel number (if any)                                *)
  146.         (*-------------------------------------------------------------------*)
  147.  
  148.         IF tnc_data.str_data[1] = '(' THEN
  149.           tnc_data.str_data := subword(@tnc_data.str_data, 2, 0);
  150.  
  151.         (*-------------------------------------------------------------------*)
  152.         (* Prep the strings                                                  *)
  153.         (*-------------------------------------------------------------------*)
  154.  
  155.         work2_str := subword(@tnc_data.str_data, 1, 2) + ' ';
  156.         work3_str := subword(@tnc_data.str_data, 1, 3) + ' ';
  157.  
  158.         (*-------------------------------------------------------------------*)
  159.         (* Handle connect requests or link resets.  Rederive user/ssid       *)
  160.         (*-------------------------------------------------------------------*)
  161.  
  162.         IF (work2_str = t_to_h_ct) OR
  163.            (work3_str = t_to_h_lrfm) OR
  164.            (work3_str = t_to_h_lrto) THEN
  165.           BEGIN;
  166.  
  167.             (*---------------------------------------------------------------*)
  168.             (* Log it as neededed                                            *)
  169.             (*---------------------------------------------------------------*)
  170.  
  171.             log_data_s('C' + port_chan_s + tnc_data.str_data + ' ' + tcb_name);
  172.  
  173.             (*---------------------------------------------------------------*)
  174.             (* Ignore LINK RESET TO                                          *)
  175.             (*---------------------------------------------------------------*)
  176.  
  177.             IF (work3_str = t_to_h_lrto) OR (work3_str = t_to_h_lrfm) THEN
  178.               EXIT;
  179.  
  180.             (*---------------------------------------------------------------*)
  181.             (* Init any part of TCB as needed                                *)
  182.             (*---------------------------------------------------------------*)
  183.  
  184.             window := window_connect;
  185.  
  186.             (*---------------------------------------------------------------*)
  187.             (* If port is locked then tell him and hang up                   *)
  188.             (*---------------------------------------------------------------*)
  189.  
  190.             IF active_port^.port_operate_mode.mode_stop_connect
  191.                                OR opt_block.operate_mode.mode_stop_connect THEN
  192.               BEGIN;
  193.                 send_message(message_port_conn_off);
  194.                 end_session(TRUE);
  195.               END;
  196.  
  197.             (*---------------------------------------------------------------*)
  198.             (* Look up call sign                                             *)
  199.             (*---------------------------------------------------------------*)
  200.  
  201.             find_call;
  202.  
  203.             IF (active_tcb^.uid_data.user_id = '')
  204.                                      AND (active_tcb^.tcb_type = th_user) THEN
  205.               extract_call
  206.             ELSE
  207.               BEGIN;
  208.                 connect_call := active_tcb^.uid_data.user_id;
  209.                 connect_ssid := active_tcb^.uid_data.user_ssid;
  210.               END;
  211.  
  212.             (*---------------------------------------------------------------*)
  213.             (* Change to any sub-port as needed                              *)
  214.             (*---------------------------------------------------------------*)
  215.  
  216.             WITH active_port^ DO
  217.               IF (port_type = port_pcpa) AND (port_num <> pcpa_port) THEN
  218.                 BEGIN;
  219.  
  220.                   (*---------------------------------------------------------*)
  221.                   (* Find the correct port                                   *)
  222.                   (*---------------------------------------------------------*)
  223.  
  224.                   this_port := main_port;
  225.                   WHILE (this_port <> NIL)
  226.                                       AND (this_port^.port_num <> pcpa_port) DO
  227.                     this_port := this_port^.rel_port;
  228.  
  229.                   (*---------------------------------------------------------*)
  230.                   (* Make sure we have a valid subport                       *)
  231.                   (*---------------------------------------------------------*)
  232.  
  233.                   IF this_port = NIL THEN
  234.                     BEGIN;
  235.                       WRITELN;
  236.                       WRITELN('*** FATAL ERROR ***');
  237.                       WRITELN('Incoming connect on undefined PC*PA port');
  238.                       WRITELN('Defined = ', active_port^.port_num);
  239.                       WRITELN('Received = ', pcpa_port);
  240.                       HALT;
  241.                     END;
  242.  
  243.                   (*---------------------------------------------------------*)
  244.                   (* Unmark the channel on one port and mark it on the other *)
  245.                   (*---------------------------------------------------------*)
  246.  
  247.                   i := channel;
  248.  
  249.                   (*---------------------------------------------------------*)
  250.                   (* Make sure all the port pointers are updated             *)
  251.                   (*---------------------------------------------------------*)
  252.  
  253.                   active_tcb^.tcb_port       := this_port;
  254.                   active_tcb^.port_chan_s[1] := this_port^.port_char;
  255.                   active_port                := this_port;
  256.  
  257.                 END;
  258.  
  259.             (*---------------------------------------------------------------*)
  260.             (* Get user's data                                               *)
  261.             (*---------------------------------------------------------------*)
  262.  
  263.             uid_i_current := find_uid(connect_call);
  264.  
  265.             (*---------------------------------------------------------------*)
  266.             (* Check for new user                                            *)
  267.             (*---------------------------------------------------------------*)
  268.  
  269.             new_user := uid_i_current = NIL;
  270.  
  271.             IF new_user THEN
  272.               BEGIN;
  273.  
  274.                 (*-----------------------------------------------------------*)
  275.                 (* Is a new user allowed?                                    *)
  276.                 (*-----------------------------------------------------------*)
  277.  
  278.                 IF active_port^.port_allow > user_c_nu THEN
  279.                   BEGIN;
  280.                     send_message(message_not_on_port);
  281.                     end_session(TRUE);
  282.                   END;
  283.  
  284.                 (*-----------------------------------------------------------*)
  285.                 (* Put new user in the tables                                *)
  286.                 (*-----------------------------------------------------------*)
  287.  
  288.                 uid_init(@active_tcb^.uid_data);
  289.  
  290.                 active_tcb^.uid_data.user_id   := connect_call;
  291.                 active_tcb^.uid_data.user_ssid := connect_ssid;
  292.  
  293.                 add_uid(@active_tcb^.uid_data);
  294.  
  295.               END
  296.             ELSE
  297.               active_tcb^.uid_data := get_uid(uid_i_current)^;
  298.  
  299.             (*---------------------------------------------------------------*)
  300.             (* Put in activity report                                        *)
  301.             (*---------------------------------------------------------------*)
  302.  
  303.             IF active_tcb^.tcb_type = th_user THEN
  304.               add_mon_call(@dummy_port,  active_port^.port_char,
  305.                                                             uid_data.user_id);
  306.  
  307.             (*---------------------------------------------------------------*)
  308.             (* Bump logon count                                              *)
  309.             (*---------------------------------------------------------------*)
  310.  
  311.             INC(active_tcb^.uid_data.user_l_cnt);
  312.  
  313.             (*---------------------------------------------------------------*)
  314.             (* Show incoming port                                            *)
  315.             (*---------------------------------------------------------------*)
  316.  
  317.             active_tcb^.uid_data.user_port := active_port^.port_char;
  318.  
  319.             (*---------------------------------------------------------------*)
  320.             (* Set up the user class                                         *)
  321.             (*---------------------------------------------------------------*)
  322.  
  323.             IF NOT new_user THEN
  324.               BEGIN;
  325.  
  326.                 IF active_tcb^.uid_data.user_class = user_c_nu THEN
  327.                   active_tcb^.uid_data.user_class := user_c_uu;
  328.  
  329.                 IF active_tcb^.uid_data.user_class > user_c_eu THEN
  330.                   active_tcb^.uid_data.user_class := user_c_eu;
  331.  
  332.                 IF (active_tcb^.uid_data.user_flag AND user_f_sysop) <> 0 THEN
  333.                   active_tcb^.uid_data.user_class := user_c_eu;
  334.  
  335.                 IF (active_tcb^.uid_data.user_flag AND user_f_bbs) <> 0 THEN
  336.                   active_tcb^.uid_data.user_class := user_c_bu;
  337.  
  338.               END;
  339.  
  340.             (*---------------------------------------------------------------*)
  341.             (* Set up MAXPAC                                                 *)
  342.             (*---------------------------------------------------------------*)
  343.  
  344.             max_pac := active_port^.max_pac;
  345.  
  346.             IF uid_data.max_pac <> 0 THEN
  347.               BEGIN;
  348.                 IF max_pac > uid_data.max_pac THEN
  349.                   max_pac := uid_data.max_pac;
  350.               END
  351.             ELSE
  352.               max_pac := active_port^.dflt_pac;
  353.  
  354.             IF max_pac = 0 THEN
  355.               max_pac := 128;
  356.  
  357.             (*---------------------------------------------------------------*)
  358.             (* Finish TCB setup                                              *)
  359.             (*---------------------------------------------------------------*)
  360.  
  361.             last_l_time := uid_data.user_l_time;
  362.  
  363.             tcb_connect := TRUE;
  364.  
  365.             EXIT;
  366.  
  367.           END; (*----- End of connect/link reset ----------------------------*)
  368.  
  369.         (*-------------------------------------------------------------------*)
  370.         (* Handle link drops                                                 *)
  371.         (*-------------------------------------------------------------------*)
  372.  
  373.         IF (work2_str = t_to_h_disc) OR
  374.            (work3_str = t_to_h_lf) THEN
  375.           BEGIN;
  376.  
  377.             (*---------------------------------------------------------------*)
  378.             (* Don't log terminal sessions or modem answers                  *)
  379.             (*---------------------------------------------------------------*)
  380.  
  381.             IF (tcb_type <> th_opr_terminal) AND (tcb_type <> th_answer) THEN
  382.               log_data_s('D' + port_chan_s + tnc_data.str_data);
  383.  
  384.             (*---------------------------------------------------------------*)
  385.             (* Update user's information                                     *)
  386.             (*---------------------------------------------------------------*)
  387.  
  388.             IF tcb_connect AND (tcb_type = th_user) THEN
  389.               BEGIN;
  390.                 uid_data.user_last   := current_day_time;
  391.                 IF active_tcb^.last_l_time
  392.                                        > active_tcb^.uid_data.user_l_time THEN
  393.                   active_tcb^.uid_data.user_l_time := active_tcb^.last_l_time;
  394.                 update_uid(@uid_data);
  395.               END;
  396.  
  397.             (*---------------------------------------------------------------*)
  398.             (* Mark channel idle                                             *)
  399.             (*---------------------------------------------------------------*)
  400.  
  401.             i := channel;
  402.  
  403.             IF (i <> 0) AND (i <= active_port^.max_chan) THEN
  404.               active_port^.connected^[i] := NIL;
  405.  
  406.             (*---------------------------------------------------------------*)
  407.             (* Destroy current task.  This call never returns!               *)
  408.             (*---------------------------------------------------------------*)
  409.  
  410.             task_destroy_active;
  411.  
  412.           END;
  413.  
  414.         (*-------------------------------------------------------------------*)
  415.         (* Log anything left                                                 *)
  416.         (*-------------------------------------------------------------------*)
  417.  
  418.         log_data_s('A' + port_chan_s + tnc_data.str_data);
  419.  
  420.       END;
  421.  
  422.   END;
  423.  
  424. (*===========================================================================*)
  425. (* Link Change pending on channel                                            *)
  426. (*===========================================================================*)
  427.  
  428. PROCEDURE link_pending;
  429.  
  430.   BEGIN;
  431.     send_recv_tnc(4);
  432.     WITH active_tcb^ DO
  433.       IF tnc_type <> t_to_h_links THEN
  434.         WRITELN('LC poll bad -- ', tnc_type, ' -- ', port_chan_s);
  435.     link_change;
  436.     task_switch;
  437.   END;
  438.  
  439. END.
  440.